import java.util.Scanner;

public class PalindromeDate {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        //在此输入您的代码...
        int in = scan.nextInt();
        in ++;
        int year = in / 10000;
        int month = (in / 100) % 100;
        int day = in % 100;
        int ret1 = 0;
        int ret2 = 0;
        while (true) {
            if (ret1 != 0) {
                break;
            }
            int yearRev = Integer.parseInt(new StringBuilder("" + year).reverse().toString());
            // 寻找下一个回文日期
            if (isTrue(year * 10000 + yearRev)) {
                if (yearRev < in % 10000 && year == in / 10000) {
                    year ++;
                    continue;
                }
                ret1 = year * 10000 + yearRev;
            } else {
                year ++;
            }
        }
        year = in / 10000;
        while (true) {
            if (ret2 != 0) {
                break;
            }
            if (!isABAB(year)) {
                int preTwo = year / 100;
                while (true) {
                    if (preTwo * 100 + preTwo > year) {
                        year = preTwo * 100 + preTwo;
                        break;
                    }
                    if (preTwo % 10 + 1 != preTwo / 10) {
                        preTwo ++;
                    } else {
                        preTwo += 2;
                    }
                }
            }
            // 到这里一定是一个ABAB的年份
            int yearRev = Integer.parseInt(new StringBuilder("" + year).reverse().toString());
            if (isTrue(year * 10000 + yearRev)) {
                if (yearRev < in % 10000 && year == in / 10000) {
                    year ++;
                    continue;
                }
                ret2 = year * 10000 + yearRev;
            } else {
                year ++;
            }
        }
        System.out.println(ret1);
        System.out.println(ret2);
        scan.close();
    }

    /**
     * 判断年份是不是ABAB类型的
     * @param year
     * @return
     */
    public static boolean isABAB(int year) {
        String str = Integer.toString(year);
        return str.charAt(0) == str.charAt(2) && str.charAt(1) == str.charAt(3);
    }

    /**
     * 判断是否是一个正常的日期
     * @param date
     * @return
     */
    public static boolean isTrue(int date) {
        int year = date / 10000, m = (date / 100) % 100, d = date % 100;
        if (m > 12 || m == 0 || d > 31) {
            return false;
        }
        if (isRun(year) && m == 2) {
            if (d > 29) {
                return false;
            }
        }
        return true;
    }

    public static boolean isRun(int year) {
        if (year % 4 == 0) {
            if (year % 100 != 0 || year % 400 == 0) {
                return true;
            }
        }
        return false;
    }
}
